iT邦幫忙

2019 iT 邦幫忙鐵人賽

DAY 9
0
自我挑戰組

大數據概念系列 第 9

Day9 | Python流程控制

  • 分享至 

  • xImage
  •  

1.最簡單的流程控制control flow

  • Equal to (==)

2 == 2 True >>> 2 == 5 False

  • Not equal to (!=)

2 != 5 True >>> 2 != 2 False

  • Less than (<)

2 < 5 True >>> 5 < 2 False

  • Less than or equal to (<=)

2 <= 2 True >>> 5 <= 2 False

  • Greater than (>)

5 > 2 True >>> 2 > 5 False

  • Greater than or equal to (>=)

5 >= 5 True >>> 2 >= 5 False

2.布林值Boolean operators
https://scontent-hkg3-1.xx.fbcdn.net/v/t1.0-9/44221396_2079484492103422_8378334558487052288_o.jpg?_nc_cat=100&amp;_nc_ht=scontent-hkg3-1.xx&amp;oh=c2d3b6b6bbfc72cfac38cb2576b0a7ea&amp;oe=5C453A1B

布林值的運算符號有三種
• and
例如
1 < 2 and 2 < 3 is True;
1 < 2 and 2 > 3 is False.
• or
例如
1 < 2 or 2 > 3 is True;
1 > 2 or 2 > 3 is False.
• Not
例如
not 41 > 40 傳回 False.

https://scontent-hkg3-1.xx.fbcdn.net/v/t1.0-9/44326140_2079484518770086_4079698389753659392_o.jpg?_nc_cat=108&amp;_nc_ht=scontent-hkg3-1.xx&amp;oh=16622292cb92807c7334c8498a4dbd6c&amp;oe=5C53B9BE

資料來源:https://www.codecademy.com/courses/learn-python/lessons/conditionals--control-flow/exercises/to-be-andor-not-to-be?action=resume_content_item

布林值的運算並不是左至右,其固定順序是

  1. not
  2. and
  3. or
    例如:True or not False and False回傳 True
    True or (not False) and False
    = True or True and False
    = True or (True and False)
    = True or False
    = True

3.Conditional Statement Syntax條件語句
例子1:
https://scontent-hkg3-1.xx.fbcdn.net/v/t1.0-9/44302782_2079484502103421_8109914152052457472_o.jpg?_nc_cat=104&amp;_nc_ht=scontent-hkg3-1.xx&amp;oh=2b482084a72ae15e9962bb915be584fa&amp;oe=5C4B77AE

例子2:
https://scontent-hkg3-1.xx.fbcdn.net/v/t1.0-9/44262487_2079484545436750_8979363971127574528_o.jpg?_nc_cat=107&amp;_nc_ht=scontent-hkg3-1.xx&amp;oh=c78c6c540eaf737e9629956cfbe69614&amp;oe=5C3C7B8B

if, else語句
https://scontent-hkg3-1.xx.fbcdn.net/v/t1.0-9/44326089_2079484558770082_7309945504983416832_o.jpg?_nc_cat=100&amp;_nc_ht=scontent-hkg3-1.xx&amp;oh=d94e1468cb6c98b6d68526dd18c09243&amp;oe=5C88A057

elif
“else if”的簡寫
例子:
https://scontent-hkg3-1.xx.fbcdn.net/v/t1.0-9/44393499_2079484585436746_8770037186494988288_o.jpg?_nc_cat=101&amp;_nc_ht=scontent-hkg3-1.xx&amp;oh=6720562919f20b0acf1f8c5ade3314fe&amp;oe=5C460B16
https://scontent-hkg3-1.xx.fbcdn.net/v/t1.0-9/44265558_2079484622103409_5166249120490323968_o.jpg?_nc_cat=100&amp;_nc_ht=scontent-hkg3-1.xx&amp;oh=2aba7a3c356a1f9fb0c4dc3be9d9daa4&amp;oe=5C423370


上一篇
Day8 | Python時間表示
下一篇
Day10 | Python函式
系列文
大數據概念30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言